1 using System.Collections;
2 using
System.Collections.Generic;
3 using
UnityEngine;
4
5 public
enum InputActionType {
6     GRAB_PIECE =
0,
7     PLACE_PIECE =
1,
8     CANCEL_PIECE =
2,
9     ZOOM_IN =
3,
10     ZOOM_OUT =
4,
11     ROTATE =
5,
12     STOP_ROTATE =
6,
13 }

14
15 public
class InputManager : Singleton<InputManager> {
16     
17     
public delegate void InputEventHandler(InputActionType actionType);
18     
public static event InputEventHandler InputEvent;
19
20     
private bool clicked;
21     
private Node currentNode;
22     
private GCPlayer currentPlayer;
23
24     
public Vector2 mouseAxis;
25
26     
public Vector2 MouseAxis {
27         
get {return mouseAxis;}
28     }
29
30     
void Awake() {
31         _destroyOnLoad = destroyOnLoad;
32         mouseAxis =
new Vector2(0,0);
33     }
34
35     
void OnDisable() {
36         InputEvent =
null;
37     }
38
39     
void Update() {
40         mouseAxis.x = Input.GetAxis(
"Mouse X");
41         mouseAxis.y = Input.GetAxis(
"Mouse Y");
42
43         
if (InputEvent == null) return;
44
45         
if (!GameManager.Instance.IsReady) return;
46
47         HighlightTile();
48
49         
if (Input.GetMouseButtonUp(0)) {
50             
if (GameManager.Instance.GameState.IsWaiting) {
51                 UnHighlightTile();
52                 InputEvent(InputActionType.GRAB_PIECE);
53             }
else if (GameManager.Instance.GameState.IsHolding) {
54                 InputEvent(InputActionType.PLACE_PIECE);
55             }
56         }
57
58         
if (Input.GetMouseButtonUp(1)) {
59             
if (GameManager.Instance.GameState.IsHolding) {
60                 InputEvent(InputActionType.CANCEL_PIECE);
61             }
62         }
63
64         
if (Input.GetAxis("Mouse ScrollWheel") > 0) {
65             InputEvent(InputActionType.ZOOM_IN);
66         }
67
68         
if (Input.GetAxis("Mouse ScrollWheel") < 0) {
69             InputEvent(InputActionType.ZOOM_OUT);
70         }
71
72         
if (Input.GetMouseButtonDown(2)) {
73             InputEvent(InputActionType.ROTATE);
74         }
else if (Input.GetMouseButtonUp(2)) {
75             InputEvent(InputActionType.STOP_ROTATE);
76         }
77     }
78
79     
public void HighlightTile() {
80         
if (GameManager.Instance.GameState.IsWaiting) {
81             UnHighlightTile();
82             currentNode = Finder.RayHitFromScreen<Node>(Input.mousePosition);
83             
if (currentNode != null) {
84                 Piece piece = currentNode.Piece;
85                 
if (piece != null) {
86                     
if (GameManager.Instance.CurrentPlayer.Has(piece)) {
87                         currentNode.HighlightMove();
88                     }
else {
89                         currentNode.HighlightEat();
90                     }
91                 }
92             }
93         }
94     }
95
96     
public void UnHighlightTile() {
97         
if (currentNode != null) {
98             currentNode.UnhighlightEat();
99             currentNode.UnhighlightMove();
100         }
101     }
102
103 }


Gõ tìm kiếm nhanh...